<template>
  <!-- 隐患处理 待审批-->
  <view class="container">
    <hidden-danger-info :detail="dangerDetail" />
    <review-info :detail="dangerDetail" />
    <view class="hidden-title" v-if="suggestion.length > 0">审批意见</view>
    <view class="background-white bor-top bottom" v-if="suggestion.length > 0">
      <approve-suggestion :suggestion="suggestion"></approve-suggestion>
    </view>
    <uni-forms ref="form" :model-value="formData" :rules="rules" labelWidth="70vw" labelPosition="top">
      <view class="background-white bor-top">
        <uni-forms-item name="result" required label="审批结果">
          <view class="flex align-center">
            <view>请选择:</view>
            <view class="acceptance-list">
              <view
                class="acceptance-item"
                v-for="(item, index) in acceptanceList"
                :key="item.dictValue"
                :class="{ active: formData.result == item.dictValue }"
                @click="formData.result = item.dictValue"
              >
                <image
                  class="icon-style"
                  v-show="formData.result != item.dictValue"
                  src="/static/images/work/dbd//selected_no.png"
                  mode="aspectFill"
                ></image>
                <image
                  class="icon-style"
                  v-show="formData.result == item.dictValue"
                  src="/static/images/work/dbd//selected_yes.png"
                  mode="aspectFill"
                ></image>
                <text class="content">{{ item.dictLabel }}</text>
              </view>
            </view>
          </view>
        </uni-forms-item>
      </view>
      <view class="background-white bor-top">
        <uni-forms-item name="resultContent" label="审核意见">
          <textarea
            v-model="formData.resultContent"
            class="text-area"
            placeholder-class="placeholder__style"
            placeholder="请填入审批意见"
            maxlength="200"
          />
        </uni-forms-item>
      </view>
    </uni-forms>
    <view class="submit-group">
      <button @click="submit" class="u-button" type="primary" :ripple="true">保存</button>
    </view>
  </view>
</template>

<script>
import { getHiddenDangerDetail } from '@/api/dbd/hiddenDangerBook'
import { checkPlanTaskApprove, getHiddenDangerReviewById } from '@/api/dbd/hiddenDangerDeal'
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
import CuCell from '@/components/cu-cell/cu-cell.vue'
import HiddenDangerInfo from './components/HiddenDangerInfo'
import ReviewInfo from './components/ReviewInfo'
import ApproveSuggestion from './components/approveSuggestion'
export default {
  components: {
    HiddenDangerInfo,
    CuCellGroup,
    CuCell,
    ReviewInfo,
    ApproveSuggestion
  },
  data() {
    return {
      dangerDetail: {},
      reviewDetail: {},
      suggestion: [],
      formData: {
        result: 1
      },
      acceptanceList: [
        {
          dictValue: 1,
          dictLabel: '通过'
        },
        {
          dictValue: 2,
          dictLabel: '不通过'
        }
      ],
      rules: {
        result: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        },
        resultContent: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        }
      }
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  onLoad({ managerId }) {
    this.managerId = managerId
    this.getHiddenDangerDetail(managerId)
  },
  methods: {
    getHiddenDangerDetail(managerId) {
      getHiddenDangerDetail(managerId).then((res) => {
        this.dangerDetail = res.data
        this.suggestion = this.dangerDetail.approvalCommentList ? this.dangerDetail.approvalCommentList : []
      })
    },

    submit() {
      this.$refs.form.validate().then((res) => {
        checkPlanTaskApprove({
          managerId: this.managerId,
          ...this.formData
        }).then(() => {
          this.$modal.msgSuccess('保存成功')
          uni.navigateBack({
            delta: 1
          })
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 200rpx;

  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx 1rpx 30rpx;

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}

.acceptance {
  margin-bottom: 10rpx;
}

.acceptance-list {
  display: flex;

  .acceptance-item {
    display: flex;
    align-items: center;
    margin-left: 20rpx;
    color: #333;

    .icon-style {
      width: 36rpx;
      height: 36rpx;
      margin-right: 10rpx;
    }

    .content {
      flex: 1;
    }
  }
}
</style>
